package gui.Main;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import communicator.GlobalObjectId;


public class GUIhelper implements Serializable
{

    private static GUI main;
    private String port;
    private String local_id;
    private GlobalObjectId global;
    //this created for the proxy
    public GUIhelper()
    {
        port = "empty";
        local_id = "empty";
    }
    public void set_helper_globalId(GlobalObjectId  myGlobal)
    {
        global = myGlobal;
    }
    public GlobalObjectId get_globalId()
    {
        return global;
    }
    //this is for the actual work
    //something probably should be done here
    public void set_GUI(GUI _main)
    {
         main = _main;
    }
    public void set_port(String _port)
    {
        port = _port;
    }
    public void set_local_id(String _local_id)
    {
        local_id = _local_id;
    }
    public String get_port()
    {
        while(port == "empty")
            System.out.print("");//timing issues?>_<

        return port;
    }
    public String get_local_id()
    {
        while(local_id == "empty"){}

        return local_id;
    }
    public void printToTracePanel(String output)
    {

        main.printToTracePanel(output);
    }
    public void addNodeGui(int value)
    {
        main.getHyPeerWebDebugger().getMapper().getNodeListing().increaseListSize(value);
        main.getHyPeerWebDebugger().getStatus().setContent("Successfully added.");
        
    }
    public void clearGui()
    {
        main.getHyPeerWebDebugger().getMapper().getNodeListing().clearGui();
    }
    
    public void updateNodeGui(ArrayList<Integer> set)
    {        
        main.getHyPeerWebDebugger().getMapper().getNodeListing().clearGui();
        
        SortedSet<Integer> list = new TreeSet<Integer>();
        if(set.size()>0){
        for(int value: set)
        {
            list.add(value);
        }
        
        for(int value:list)
        {
            main.getHyPeerWebDebugger().getMapper().getNodeListing().increaseListSize(value); 
        }
        }
    }
    
}
